Skip to main content

Updating Reference Data From an App

As part of an apps process you might want to update some data held in a reference table. For example, maybe you have an app where a user enters a currency exchange rate and the app then writes the value back to the 'Currencies' reference table. We can achieve this as a 'SendHttpProcess' process step using the 'Update Reference Data by Key' API referred to in the previous section of this help.

The process will first need a 'Get Current Record' step as described in the 'Routing Steps' section of this help. We then need a 'SendHttpRequest' process step in which we can construct a URL to use the api/referencedataentry/keybatch endpoint. We can use the CurrentRecord.Result to get the details of the current record dynamically and insert them in to the URL.

Constructing the URL

The format of the URL is:

/api/referencedataentry/keybatch?referenceDataId=<reference data table ID>&Key=<reference data item key>

The key is the unique key field of the reference data table, the table ID is the unique ID associated with the table you are writing back to which is available in the URL in the browser address bar when you view the reference data table. We can use the JSON.parse formula to drop values from the form into the URL, so an example URL might be:

"https://demo.unifiplatform.com/api/referencedataentry/keybatch?referenceDataId=1daad16928f14986bd09784e3c6e13ad&Key=" + JSON.parse(CurrentRecord.Result).reference_data_item_key;

In this example the field ID reference_data_item_key holds the key value (e.g. currency code) so we can use the formula

JSON.parse(CurrentRecord.Result).reference_data_item_key

to add this to the URL. This is 'Javascript' so change the URL type accordingly.

The content field will contain the body of the request in JSON format, and again we can drop in values from the app using the JSON.parse convention. So our content might look like this:

'{"exchange_rate": "' + JSON.parse(CurrentRecord.Result).new_rate + '"}'

In this example, new_rate is the field we want to load in to the exchange_rate column of the reference data table. Add the x-api-key parameter into the request headers with your API Key in JSON format and your final request should look something like this:

 alt image